<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>吕梁健康体检预约系统</title><!--666-->
    <meta name="description" content="吕梁健康体检预约系统">
    <meta name="keywords" content="吕梁健康体检预约系统">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../css/login.css">
</head>
<body class="hold-transition skin-purple sidebar-mini">
<div id="app">
    <div class="login-container">
        <div class="loginBox">
            <form method="post" class="login-form" id="loginForm">
                <div class="title-container">
                    <div class="logoInfo clearfix">
                        <em class="logo"></em>
                    </div>
                </div>
                <div class="item">
                        <span class="svg-container svg-container_login">
                          <span class="user"></span>
                        </span>
                    <input type="text" id="username" v-model="formData.username" name="username" placeholder="请输入用户名"/>
                    <span id="count-msg" class="error"></span>
                </div>
                <div class="item">
                        <span class="svg-container">
                          <span class="username"></span>
                        </span>
                    <input type="password" id="password" v-model="formData.password" name="password"
                           placeholder="请输入密码"/>
                        <span id="password-msg" class="error"></span>
                </div>
                <div class="item loginBtn">
                    <input type="button" style="width:100%;margin-bottom:30px;" value="登录" @click="login()"/>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script src="../js/jquery-heima-0.0.1.js"></script>
<script type="text/javascript" src="../js/login.js"></script>
<script>
    // axios跨域访问，如果需要携带cookie，withCredentials必须为true
    axios.defaults.withCredentials = true;
    var vue = new Vue({
        el: '#app',
        data: {
            backend_url: "http://localhost:9002",
            formData: {
                username: "",
                password: ""
            }
        },
        created() {
            var that = this;
            document.onkeydown = function (e) {
                var key = window.event.keyCode;
                if (key === 13) {
                    that.login();
                }
            };
        },
        //http://localhost:8080/login.html
        methods: {
            //登录
            login() {
                //发起http post请求
                /*
                * 加入security组件后不能发送json格式请求,
                * 必须将表单数据序列化*/
                var param = $("#loginForm").serialize();

                axios.post(this.backend_url + "/user/login", param).then((response) => {
                    if (response.data.flag) {
                        //请求成功--->跳转至main.html
                        location.href = "main.html";
                    } else {
                        //请求失败
                        this.$message.error(response.data.message);
                    }
                }).catch((error) => {
                    console.log(error);
                    this.$message.error("网络异常");
                });
            }
        }
    });
</script>
<script type="text/javascript">
    window.onload = function() {
        var config = {
            vx : 4,
            vy : 4,
            height : 2,
            width : 2,
            count : 100,
            color : "121, 162, 185",
            stroke : "100, 200, 180",
            dist : 6000,
            e_dist : 20000,
            max_conn : 10
        }
        CanvasParticle(config);
    }
</script>
<script type="text/javascript" src="../js/canvas-particle.js"></script>
</html>
